/*
 * Interface gráfica para a consulta de mençao final de um aluno em uma disciplina.
 */
package amanda_gabriel_isabella_lucivania_monica.View;

import amanda_gabriel_isabella_lucivania_monica.Model.Dao.DaoBaseImpl;
import amanda_gabriel_isabella_lucivania_monica.Model.Pojo.Aluno;
import amanda_gabriel_isabella_lucivania_monica.Model.Pojo.Disciplina;
import amanda_gabriel_isabella_lucivania_monica.Model.Pojo.HistoricoDisciplina;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

/**
 * Interface gráfica de consultar menção final
 *
 * @author lucy
 */
public class ConsultarMencaoFinalIG extends javax.swing.JFrame {

    private DaoBaseImpl daoBaseImpl;

    /**
     * Cria um novo form ConsultarMencaoFinalIG
     */
    public ConsultarMencaoFinalIG(DaoBaseImpl daoBaseImpl) {
        initComponents();
        jTAprovacao.setEditable(false);
        jTNotaFinal.setEditable(false);
        this.daoBaseImpl = daoBaseImpl;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        jDCamposVazios = new javax.swing.JDialog();
        jLabel5 = new javax.swing.JLabel();
        jBOK = new javax.swing.JButton();
        amanda_gabriel_isabella_lucivania_monicaPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("amanda_gabriel_isabella_lucivania_monicaPU").createEntityManager();
        alunoQuery = java.beans.Beans.isDesignTime() ? null : amanda_gabriel_isabella_lucivania_monicaPUEntityManager.createQuery("SELECT a FROM Aluno a");
        alunoList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : alunoQuery.getResultList();
        disciplinaQuery = java.beans.Beans.isDesignTime() ? null : amanda_gabriel_isabella_lucivania_monicaPUEntityManager.createQuery("SELECT d FROM Disciplina d");
        disciplinaList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : disciplinaQuery.getResultList();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jCBNome = new javax.swing.JComboBox();
        jCBDisciplina = new javax.swing.JComboBox();
        jBCancelar = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jTNotaFinal = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTAprovacao = new javax.swing.JTextField();
        jBConsultar = new javax.swing.JButton();

        jDCamposVazios.setTitle("ATENÇÃO");
        jDCamposVazios.setMinimumSize(new java.awt.Dimension(400, 175));

        jLabel5.setText("Todos os campos devem ser preenchidos!");

        jBOK.setText("OK");
        jBOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBOKActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDCamposVaziosLayout = new javax.swing.GroupLayout(jDCamposVazios.getContentPane());
        jDCamposVazios.getContentPane().setLayout(jDCamposVaziosLayout);
        jDCamposVaziosLayout.setHorizontalGroup(
            jDCamposVaziosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDCamposVaziosLayout.createSequentialGroup()
                .addContainerGap(57, Short.MAX_VALUE)
                .addGroup(jDCamposVaziosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDCamposVaziosLayout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(22, 22, 22))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDCamposVaziosLayout.createSequentialGroup()
                        .addComponent(jBOK, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(140, 140, 140))))
        );
        jDCamposVaziosLayout.setVerticalGroup(
            jDCamposVaziosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDCamposVaziosLayout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addComponent(jLabel5)
                .addGap(18, 18, 18)
                .addComponent(jBOK)
                .addContainerGap(42, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Menção Final");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Informe os dados abaixo:"));

        jLabel1.setText("Nome:");

        jLabel2.setText("Disciplina:");

        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, alunoList, jCBNome);
        bindingGroup.addBinding(jComboBoxBinding);

        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, disciplinaList, jCBDisciplina);
        bindingGroup.addBinding(jComboBoxBinding);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jCBNome, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                        .addComponent(jCBDisciplina, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jCBDisciplina, jCBNome});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jCBNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(16, 16, 16)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jCBDisciplina, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(63, Short.MAX_VALUE))
        );

        jBCancelar.setText("Cancelar");
        jBCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCancelarActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Resultado:"));

        jLabel3.setText("Nota Final:");

        jTNotaFinal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTNotaFinalActionPerformed(evt);
            }
        });

        jLabel4.setText("Aprovação:");

        jTAprovacao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTAprovacaoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTNotaFinal, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTAprovacao, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTNotaFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTAprovacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(41, Short.MAX_VALUE))
        );

        jBConsultar.setText("Consultar");
        jBConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBConsultarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jBCancelar)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jBConsultar)
                .addGap(20, 20, 20))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jBConsultar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addComponent(jBCancelar)
                .addGap(23, 23, 23))
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCancelarActionPerformed
        setVisible(false);
    }//GEN-LAST:event_jBCancelarActionPerformed

    private void jBConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBConsultarActionPerformed
        Aluno aluno = (Aluno) jCBNome.getSelectedItem();
        Disciplina disciplina = (Disciplina) jCBDisciplina.getSelectedItem();

        if ((jCBNome.getSelectedIndex() == -1) || (jCBDisciplina.getSelectedIndex() == -1)) {
            jDCamposVazios.setVisible(true);
            setVisible(false);
        } else {
            String query = "select h from Aluno a join a.historicoDisciplina h join h.disciplina d where a.id = :idAluno and d.id = :idDisciplina";

            List<Integer> dados = new ArrayList<Integer>();
            List<String> parametros = new ArrayList<String>();
            
            dados.add(aluno.getIdPessoa());
            parametros.add("idAluno");
            
            dados.add(disciplina.getId());
            parametros.add("idDisciplina");

            List<Objects> listaResultados = (List<Objects>) daoBaseImpl.executarQuery(query, dados, parametros);

            if (listaResultados.size() == 1) {

                for (Iterator<Objects> it = listaResultados.iterator(); it.hasNext();) {
                    //Objects objects = (HistoricoDisciplina) it.next();
                    //HistoricoDisciplina historicoDisciplina = (HistoricoDisciplina) objects;
                    //jTNotaFinal.setText(""+historicoDisciplina.getNota());
                    //jTAprovacao.setText(""+historicoDisciplina.getAprovacao());
                }
            }

        }
    }//GEN-LAST:event_jBConsultarActionPerformed

    private void jTNotaFinalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTNotaFinalActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTNotaFinalActionPerformed

    private void jTAprovacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTAprovacaoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTAprovacaoActionPerformed

    private void jBOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBOKActionPerformed
        setVisible(true);
        jDCamposVazios.dispose();
    }//GEN-LAST:event_jBOKActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.util.List<amanda_gabriel_isabella_lucivania_monica.Model.Pojo.Aluno> alunoList;
    private javax.persistence.Query alunoQuery;
    private javax.persistence.EntityManager amanda_gabriel_isabella_lucivania_monicaPUEntityManager;
    private java.util.List<amanda_gabriel_isabella_lucivania_monica.Model.Pojo.Disciplina> disciplinaList;
    private javax.persistence.Query disciplinaQuery;
    private javax.swing.JButton jBCancelar;
    private javax.swing.JButton jBConsultar;
    private javax.swing.JButton jBOK;
    private javax.swing.JComboBox jCBDisciplina;
    private javax.swing.JComboBox jCBNome;
    private javax.swing.JDialog jDCamposVazios;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField jTAprovacao;
    private javax.swing.JTextField jTNotaFinal;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
